package com.gouwudai.gobbs.service.impl;

import java.util.List;

import org.extremecomponents.table.limit.Limit;

import com.gouwudai.gobbs.common.Constants;
import com.gouwudai.gobbs.common.IPageList;
import com.gouwudai.gobbs.dao.IAreaDAO;
import com.gouwudai.gobbs.pojo.TbbsArea;
import com.gouwudai.gobbs.service.IAreaService;
import com.litt.core.util.ExtremeTableUtil;

public class AreaServiceImpl implements IAreaService
{
	IAreaDAO areaDAO;
	
	public void save(TbbsArea tbbsArea)
	{	
		areaDAO.save(tbbsArea);		
	}

	public TbbsArea load(Integer id)
	{
		return (TbbsArea)areaDAO.load(id);
	}

	public void update(TbbsArea tbbsArea)
	{
		areaDAO.update(tbbsArea);
	}

	public void delete(Integer Id)
	{
		areaDAO.delete(Id);
	}
	
	/**
	 * 返回该省下的所有城市，中间用逗号分开，供页面生成下拉列表
	 * @param areaId
	 * @return
	 */
	public String getSubCitiesOptions(Integer areaId)
    {
        StringBuilder sb = new StringBuilder(200);
        List list = areaDAO.listSubCities(areaId);
        for (int i = 0; i < list.size(); i++)
        {
            sb.append(list.get(i));
            sb.append(",");
        }
        return sb.toString();
    }
	
	public IPageList listPage(int pageIndex,int pageSize,String sort)
	{
		return areaDAO.listPage(pageIndex, pageSize,sort);
	}
	
    public List listByType(int areaType)
    {
    	return areaDAO.listByType(areaType);
    }
	
	public void AutoBindingTable(javax.servlet.http.HttpServletRequest request)
	{
		Limit limit = ExtremeTableUtil.getLimit(request, Constants.DEFAULT_PAGE_SIZE);
		IPageList page = this.listPage(limit.getPage(), limit.getCurrentRowsDisplayed(),ExtremeTableUtil.getSort(limit));
		request.setAttribute("resultList",page.getRsList());
		request.setAttribute("totalRows",page.getTotalSize());
	}

	public void setAreaDAO(IAreaDAO areaDAO) {
		this.areaDAO = areaDAO;
	}
	
}